package com.brave.service.controller;

import com.brave.base.BaseController;
import com.brave.base.CheckNullParamKit;
import com.brave.base.RedisKit;
import com.brave.service.dto.FindServiceListByTypeDTO;
import com.brave.service.service.ServiceQueryService;
import com.brave.user.dto.RedisUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(value = "服务模块", tags = "服务模块", description = "服务模块")
@RestController
@RequestMapping("/v1/service")
public class ServiceQueryController extends BaseController
{
    @Autowired
    private RedisKit redisKit;
    @Autowired
    private ServiceQueryService serviceQueryService;


    @ApiOperation(value = "获取所有的服务类型")
    @GetMapping(value = "/findServiceTypeList", produces = "application/json")
    public String findServiceTypeList(@RequestHeader String token)
    {
        //校验身份
        RedisUserInfo redisUserInfo = redisKit.checkUserToken(token);
        if(null == redisUserInfo)
        {
            return tokenBadRequest();
        }
        //查询出所有的服务类型
        return serviceQueryService.findServiceTypeList();
    }
    
    
    
    @ApiOperation(value = "根据服务类型查询对应的服务列表")
    @ApiImplicitParam(name = "dto", value = "查询参数", required = true, dataType = "FindServiceListByTypeDTO")
    @PostMapping(value = "/findServiceListByType", produces = "application/json")
    public String findServiceListByType(@RequestHeader String token, @RequestBody FindServiceListByTypeDTO dto)
    {
        RedisUserInfo redisUserInfo = redisKit.checkUserToken(token);
        if(null == redisUserInfo)
        {
            return tokenBadRequest();
        }
        //
        Map<String, String> checkMap = CheckNullParamKit.checkParam(dto);
        if(0 != checkMap.size())
        {
            return badParameter(checkMap);
        }
        //调用业务逻辑
        return serviceQueryService.findServiceListByType(dto);
    }
    
    
   
    
    
    
}